from output import Output
from plugin_system import Plugin

class PrintOutput(Output):
    def __init__(self, freq=None):
        """
        Takes the frequency at which the
        data will be printed.
        """
        self.frequency = freq

    def output(self, obj, step):
        if step % self.frequency == 0:
            s = "Step: %s, Time: %s, Kinetic Energy: %s, Potential Energy: %s, Total Energy: %s \n" % \
                (step, obj.simulated_time, obj.kinetic_energy, obj.potential_energy, \
                     obj.kinetic_energy + obj.potential_energy)
            print s


class PrintOutputPluginAdapter(Plugin, PrintOutput):
    plugin_name = "PrintOutput"
    parameter_definitions = {"freq" : (int, True, "Frequency (in steps) at which to write data.")}
    
    def __init__(self, *args, **user_params):
        params = self.configure_parameters(**user_params)
        PrintOutput.__init__(self, freq=params["freq"])
